package com.tbit.uqbike.object.pojo;

import com.tbit.uqbike.object.pojo.vo.*;
import com.tbit.uqbike.webmanager.util.NumberUtils;
import lombok.Data;

import java.math.BigDecimal;
import java.util.Map;

/**
 * @AUTHOR: wei.xing
 * @DATE: 2022-12-06 20:34
 **/
@Data
public class TotalDetailData {

    /**
     * 其他收入
     */
    public BigDecimal otherIncome;

    /**
     * 其他支出
     */
    public BigDecimal otherExpenses;

    /**
     * 其他
     */
    public BigDecimal other;

    /**
     * 微信商户
     */
    public BigDecimal wechat;
    /**
     * 支付宝商户
     */
    public BigDecimal alipay;
    /**
     * 汇付商户
     */
    public BigDecimal remittance;

    /**
     * 商户统计(公式=微信商户+支付宝商户+汇付商户)
     */
    public BigDecimal merchant;


    /**
     * 骑行
     */
    public BigDecimal cycling;

    /**
     * 用户罚款
     */
    public BigDecimal userFine;

    /**
     * 购卡
     */
    public BigDecimal purchase;

    /**
     * 退款
     */
    public BigDecimal refund;
    /**
     * 运营营收(公式=骑行费用+用户罚款+用户购卡-退款)
     *
     * @return
     */
    public BigDecimal operation;


    /**
     * 预存款收入，不包含手工
     *
     * @return
     */
    public BigDecimal advanceDepositIncome;

    /**
     * 预存款支出，不包含手工
     *
     * @return
     */
    public BigDecimal advanceDepositExpenses;


    /**
     * 预存款
     *
     * @return
     */
    public BigDecimal advanceDeposit;


    /**
     * 押金收入
     *
     * @return
     */
    public BigDecimal userDepositIncome;

    /**
     * 押金支出
     *
     * @return
     */
    public BigDecimal userDepositExpenses;


    /**
     * 押金
     *
     * @return
     */
    public BigDecimal userDeposit;


    /**
     * 商户统计(公式=运营营收+预存款+押金+其他收支)
     *
     * @return
     */
    public BigDecimal merchantStat;


    public void calculateOther(Map<String, Object> otherDataMap) {
        otherIncome = new BigDecimal(otherDataMap.get("otherIncomeMoney").toString()).setScale(2, BigDecimal.ROUND_DOWN);
        otherExpenses = new BigDecimal(otherDataMap.get("otherExpensesMoney").toString()).setScale(2, BigDecimal.ROUND_DOWN);
        other = otherIncome.subtract(otherExpenses).setScale(2, BigDecimal.ROUND_DOWN);
    }

    public void calculateDeposit(DepositTotalIncomeVO totalIncome) {
        userDepositIncome = BigDecimal.valueOf(totalIncome.getIncomeMoney()).setScale(2, BigDecimal.ROUND_DOWN);
        userDepositExpenses = BigDecimal.valueOf(totalIncome.getExpenseMoney()).setScale(2, BigDecimal.ROUND_DOWN);
        userDeposit = userDepositIncome.subtract(userDepositExpenses).setScale(2, BigDecimal.ROUND_DOWN);
    }

    public void calculateAdvanceDeposit(AdvanceDepositTotalIncomeVO manualTotalAdvanceDeposit) {
        advanceDepositIncome = BigDecimal.valueOf(manualTotalAdvanceDeposit.getIncomeMoney()).setScale(2, BigDecimal.ROUND_DOWN);
        advanceDepositExpenses = BigDecimal.valueOf(manualTotalAdvanceDeposit.getExpenseMoney()).setScale(2, BigDecimal.ROUND_DOWN);
        advanceDeposit = advanceDepositIncome.subtract(advanceDepositExpenses).setScale(2, BigDecimal.ROUND_DOWN);

    }

    public void calculateMerchant(TransactionOrderTotalIncomeVO weChat, TransactionOrderTotalIncomeVO alipay, TransactionOrderTotalIncomeVO remittance) {
        this.wechat = NumberUtils.sub(weChat.getIncomeSuccessMoney(), weChat.getExpenseSuccessMoney()).setScale(2, BigDecimal.ROUND_DOWN);
        this.alipay = NumberUtils.sub(alipay.getIncomeSuccessMoney(), alipay.getExpenseSuccessMoney()).setScale(2, BigDecimal.ROUND_DOWN);
        this.remittance = NumberUtils.sub(remittance.getIncomeSuccessMoney(), remittance.getExpenseSuccessMoney()).setScale(2, BigDecimal.ROUND_DOWN);
        merchant = NumberUtils.add(this.wechat, this.alipay, this.remittance).setScale(2, BigDecimal.ROUND_DOWN);
    }

    public void calculateOperation(RideLogDetailsSumVO rideLogDetailsSum, PayCardLogSumVO payCardLogSum, RefundLogSum refundLogSum) {
        cycling = BigDecimal.valueOf(rideLogDetailsSum.getCyclingMoney()).setScale(2, BigDecimal.ROUND_DOWN);
        userFine = BigDecimal.valueOf(rideLogDetailsSum.getFineMoney()).setScale(2, BigDecimal.ROUND_DOWN);
        purchase = BigDecimal.valueOf(payCardLogSum.getUserByCardMoney()).setScale(2, BigDecimal.ROUND_DOWN);
        refund = BigDecimal.valueOf(refundLogSum.getCashRefundSumMoney()).setScale(2, BigDecimal.ROUND_DOWN);
        operation = NumberUtils.add(cycling, userFine, purchase).subtract(refund).setScale(2, BigDecimal.ROUND_DOWN);
    }

    public void calculateMerchantStat() {
        merchantStat = NumberUtils.add(operation, other, userDeposit, advanceDeposit).setScale(2, BigDecimal.ROUND_DOWN);
    }
}
